package qunartest02;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class WzpTest {

    public static void main(String[] args) {
        double d = 301353.05;
        BigDecimal decimal = new BigDecimal(d);
        System.out.println(decimal);//301353.0499999999883584678173065185546875
        System.out.println(decimal.setScale(1, RoundingMode.HALF_UP));//301353.0
        System.out.println(new BigDecimal(0.1));
        Object deserialize = deserialize(hexToByteArray("\\xac\\xed\\x00\\x05sr\\x00\\x11java.lang.Integer\\x12\\xe2\\xa0\\xa4\\xf7\\x81\\x878\\x02\\x00\\x01I\\x00\\x05valuexr\\x00\\x10java.lang.Number\\x86\\xac\\x95\\x1d\\x0b\\x94\\xe0\\x8b\\x02\\x00\\x00xp|\\x1e\\xa44"));
        System.out.println(deserialize);
    }

    public static byte[] hexToByteArray(String inHex){
        int hexlen = inHex.length();
        byte[] result;
        if (hexlen % 2 == 1){
            //奇数
            hexlen++;
            result = new byte[(hexlen/2)];
            inHex="0"+inHex;
        }else {
            //偶数
            result = new byte[(hexlen/2)];
        }
        int j=0;
        for (int i = 0; i < hexlen; i+=2){
            result[j]=(byte)Integer.parseInt(inHex.substring(i,i+2),16);
            j++;
        }
        return result;
    }

    public static Object deserialize(byte[] byteArray) throws NullPointerException {
        if (byteArray != null && byteArray.length != 0) {
            ByteArrayInputStream in = new ByteArrayInputStream(byteArray);
            ObjectInputStream objStream = null;
            Object obj = null;

            try {
                objStream = new ObjectInputStream(in);
                obj = objStream.readObject();
            } catch (Exception var13) {
                System.out.println(var13);
            } finally {
                try {
                    if (objStream != null) {
                        objStream.close();
                    }
                } catch (IOException var12) {
                    System.out.println(var12);
                }

            }
            return obj;
        } else {
            throw new NullPointerException("SerializeUtil.deserialize() byteArray == null or length is 0");
        }
    }
}
